
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body  >
<div class="layui-upload">
    <fieldset class="layui-elem-field  " style="margin-top: 20px;height: 430px">
        <legend>客户文件信息</legend>
        <form class=" layui-form">
        <div class="layui-form-item">
        <input   name="khid"   type="hidden" id="khid">
        </div>
        </form>
        <script type="text/html" id="opera">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="down">下载</a>

            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <table id="fileInfo" lay-filter="fileInfo"></table>

    </fieldset>
</div>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script>
    //多文件列表示例
    layui.use(['table','form','layer','upload'],function () {
        var table = layui.table;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var $ = layui.$;

        var url = contextPath+"/files/"+$("#khid").val();
        console.log(url);
        $.ajax({
            url: url,
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                table.render({
                    elem:'#fileInfo'
                    ,page:true
                    ,cellMinWidth: 80
                    ,data: res.list
                    ,cols: [[
                        {type:'numbers', title: '序号',  align:'center'}
                        ,{field:'filename', title: '文件名称' ,align: 'center' } //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增

                        ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera' ,width:150}

                    ]]
                });
            }
        });
        //监听工具条
        table.on('tool(fileInfo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'down'){
                console.log(contextPath+"/files?fileid="+data.fileid);

                window.location.href = contextPath+"/files?fileid="+data.fileid;

            } else if(layEvent === 'del'){
                console.log(data);
                layer.confirm('确定删除?', function(index){
                    $.ajax({
                        url: contextPath+"/files/"+data.fileid,
                        type: "DELETE",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {



                            obj.del(); //删除对应行（tr）的DOM结构
                            layer.msg(res.message);
                        }
                    });

                    layer.close(index);
                    //向服务端发送删除指令
                });
            }
        });
    });

</script>
</body>